import React from 'react';
import './prescriptionTemplate.less';
import ajax from '../../../common/ajax';
import {browserHistory} from 'react-router';
import { Button, Table, Modal, Pagination, Form, message} from 'antd';
//此为处方模拟数据
const data = [{
    id:'1',
    prescriptionName:'头晕',
    prescriptionItem:'金银花（1g）；半夏（12克）；柴胡（5克）；黄芩（6克）；枳实（15克）；芍药（6克）；大黄改（9克）',
    relatedDepartment:'内科',
    createdPerson:'张医生',
    createdTime: '2017-12-12 15:30',
    status:'1',
}
];

class PrescriptionTemplate extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            storeList:data,//门店列表
            pagesize: 10,// 每页显示的页数
            pageindex: 1,// 当前页
            storesCount:0,//门店总数
        }
    }
    componentDidMount() {
        //获取医生挂号费列表
        this.getDepartmentsList();
    }
    //获取医生挂号费列表
    getDepartmentsList() {
        // ajax('get','').then(data=>{
        //     this.setState({
        //         storeList:data
        //     })
        // }).catch(err=>{
        //         console.log(err);
        //     })
    }
    //分页
    changePage(pageindex) {
        this.setState({
            pageindex
        }, () => {
            this.getStoreList();
        });
    }

    //删除医生挂号费数据
    deleteDepartment(store) {
        Modal.confirm({
            title: '删除门店',
            content: '确认删除该挂号费数据吗?',
            cancelText:'取消',
            okText:'确定',
            onCancel: () => { message.info('取消删除该挂号费数据') },
            onOk: () => {
                //发送Ajax请求
            }
        })
    }
    //编辑医生挂号费信息
    editDepartment(store) {
        console.log(store);
        let paths = {
            pathname: 'addStoreForm',
            state: JSON.stringify(store),
        }
        browserHistory.push({
            pathname:paths.pathname,
            query:{},
            state:'haha'
        });
    }

    render() {
        const columns = [
            {
                title: '序号',
                dataIndex: 'id',
                width: 50,
            },
            {
                title: '处方模板名称',
                dataIndex: 'prescriptionName',
                width: 80,
            }, {
                title: '关联科室',
                dataIndex: 'relatedDepartment',
                width: 80,
            },{
                title: '模板项目',
                dataIndex: 'prescriptionItem',
                width: 220,
            }, {
                title: '创建人',
                dataIndex: 'createdPerson',
                width: 80,
            }, {
                title: '创建日期',
                dataIndex: 'createdTime',
                width: 120,
            },{
                title: '状态',
                dataIndex: 'status',
                width: 50,
                render: text => <Button type={text == 1 ? "danger" :"primary" }>{text == 1 ? "停用" : text == 0 ? "正常" : ""}</Button>
            }, {
                title: '操作',
                width: 200,
                render: (text, record) => (
                    <div>
                        <Button onClick={this.editDepartment.bind(this, record)} type="primary" >编辑</Button>
                        <Button onClick={this.deleteDepartment.bind(this, record)}  type="danger">删除</Button>
                    </div>
                )
            }
        ];
        return (
            <div className="container">
                <div className="store-manage-content">
                    {/*增加按钮*/}
                    <div className="storeAdd">
                        <Button onClick={() => { browserHistory.push('addPrescriptionTemplateForm') }}  type="primary">
                            <img src={require('../../../../images/add.png')} alt=""/>新增处方模板</Button>
                    </div>
                    {/*处方模板列表 */}
                    <div className='all-roles-table'>
                        <Table
                            rowKey="id"
                            columns={columns}
                            dataSource={data}
                            pagination={false}
                            bordered
                        />
                    </div>
                    {/*分页*/}
                    <div className="pagination">
                        <Pagination current={this.state.pageindex} total={this.state.managersCount || 1} defaultPageSize={this.state.pagesize} onChange={this.changePage.bind(this)} />
                    </div>
                </div>
            </div>
        )
    }
}
export default PrescriptionTemplate;